﻿namespace rtgen_guiclient
{
    using Microsoft.Win32;
    using rtgen_guiclient.Properties;
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Windows.Forms;

    public class Userdata : Form
    {
        private Button btnCancel;
        private Button btnLogin;
        private CheckBox cbProxy;
        private CheckBox cbStartup;
        private IContainer components;
        private GroupBox groupBox1;
        private GroupBox groupBox2;
        private Label label1;
        private Label label2;
        private Label label3;
        private Label label4;
        private Label label6;
        private Label label7;
        private Label lblRegister;
        private string startupKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
        private MaskedTextBox txtPassword;
        private TextBox txtProxyDomain;
        private MaskedTextBox txtProxyPassword;
        private TextBox txtProxyUsername;
        private TextBox txtUsername;

        public Userdata()
        {
            this.InitializeComponent();
            this.txtUsername.Text = Settings.Default.Username;
            this.txtPassword.Text = Settings.Default.Password;
            if (Settings.Default.ProxyUsername != "")
            {
                this.txtProxyUsername.Text = Settings.Default.ProxyUsername;
                this.txtProxyPassword.Text = Settings.Default.ProxyPassword;
                this.txtProxyDomain.Text = Settings.Default.ProxyDomain;
                this.cbProxy.Checked = true;
            }
            if (((string) Registry.CurrentUser.CreateSubKey(this.startupKey).GetValue("DistrRTgen")) != null)
            {
                this.cbStartup.Checked = true;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            base.Close();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (this.txtUsername.Text == "")
            {
                MessageBox.Show("Username is empty");
            }
            else if (this.txtPassword.Text == "")
            {
                MessageBox.Show("Password is empty");
            }
            else
            {
                if (this.cbProxy.Checked)
                {
                    if (this.txtProxyUsername.Text == "")
                    {
                        MessageBox.Show("Username for proxy authentication is empty");
                        return;
                    }
                    if (this.txtProxyPassword.Text == "")
                    {
                        MessageBox.Show("Password for proxy authentication is empty");
                        return;
                    }
                }
                string text = this.btnLogin.Text;
                this.btnLogin.Text = "Logging in...";
                this.btnLogin.Refresh();
                Settings.Default.Username = this.txtUsername.Text;
                Settings.Default.Password = this.txtPassword.Text;
                if (this.cbProxy.Checked)
                {
                    Settings.Default.ProxyUsername = this.txtProxyUsername.Text;
                    Settings.Default.ProxyPassword = this.txtProxyPassword.Text;
                    Settings.Default.ProxyDomain = this.txtProxyDomain.Text;
                }
                else
                {
                    Settings.Default.ProxyUsername = Settings.Default.ProxyPassword = Settings.Default.ProxyDomain = "";
                }
            }
        }

        private void cbProxy_CheckedChanged(object sender, EventArgs e)
        {
            if (this.cbProxy.Checked)
            {
                this.txtProxyPassword.Enabled = this.txtProxyUsername.Enabled = this.txtProxyDomain.Enabled = true;
            }
            else
            {
                this.txtProxyPassword.Enabled = this.txtProxyUsername.Enabled = this.txtProxyDomain.Enabled = false;
            }
        }

        private void cbStartup_CheckedChanged(object sender, EventArgs e)
        {
            RegistryKey key = Registry.CurrentUser.CreateSubKey(this.startupKey);
            if (this.cbStartup.Checked)
            {
                key.SetValue("DistrRTgen", Application.StartupPath + @"\DistrRTgen.exe /hide", RegistryValueKind.String);
            }
            else
            {
                key.DeleteValue("DistrRTgen", false);
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.txtUsername = new TextBox();
            this.txtPassword = new MaskedTextBox();
            this.label1 = new Label();
            this.label2 = new Label();
            this.btnLogin = new Button();
            this.label4 = new Label();
            this.lblRegister = new Label();
            this.label6 = new Label();
            this.label7 = new Label();
            this.cbStartup = new CheckBox();
            this.groupBox1 = new GroupBox();
            this.groupBox2 = new GroupBox();
            this.txtProxyDomain = new TextBox();
            this.cbProxy = new CheckBox();
            this.txtProxyUsername = new TextBox();
            this.txtProxyPassword = new MaskedTextBox();
            this.label3 = new Label();
            this.btnCancel = new Button();
            Label label = new Label();
            Label label2 = new Label();
            Label label3 = new Label();
            Label label4 = new Label();
            Label label5 = new Label();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            base.SuspendLayout();
            label.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            label.Location = new Point(0x37, 0x87);
            label.Name = "label5";
            label.Size = new Size(0x103, 0x2d);
            label.TabIndex = 8;
            label.Text = "Remember that you only need one registered account for as many computers as you wish to run DistrRTgen.";
            label2.Location = new Point(0x2d, 130);
            label2.Name = "label11";
            label2.Size = new Size(0x100, 0x38);
            label2.TabIndex = 0x13;
            label2.Text = "DistrRTgen will automaticly detect your proxy settings from Internet Explorer. If your proxy server requires authentication, use these settings to configure it";
            label3.AutoSize = true;
            label3.Font = new Font("Tahoma", 10f, FontStyle.Regular, GraphicsUnit.Point, 0);
            label3.Location = new Point(10, 0x2d);
            label3.Name = "label8";
            label3.Size = new Size(0x4a, 0x11);
            label3.TabIndex = 0x10;
            label3.Text = "Username:";
            label4.AutoSize = true;
            label4.Font = new Font("Tahoma", 10f, FontStyle.Regular, GraphicsUnit.Point, 0);
            label4.Location = new Point(10, 0x48);
            label4.Name = "label9";
            label4.Size = new Size(0x47, 0x11);
            label4.TabIndex = 0x10;
            label4.Text = "Password:";
            label5.AutoSize = true;
            label5.Font = new Font("Tahoma", 10f, FontStyle.Regular, GraphicsUnit.Point, 0);
            label5.Location = new Point(10, 0x61);
            label5.Name = "label10";
            label5.Size = new Size(60, 0x11);
            label5.TabIndex = 0x15;
            label5.Text = "Domain:";
            this.txtUsername.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.txtUsername.Location = new Point(0x63, 0x25);
            this.txtUsername.Name = "txtUsername";
            this.txtUsername.Size = new Size(0x8e, 0x15);
            this.txtUsername.TabIndex = 0;
            this.txtPassword.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.txtPassword.Location = new Point(0x63, 0x3f);
            this.txtPassword.Name = "txtPassword";
            this.txtPassword.PasswordChar = '*';
            this.txtPassword.Size = new Size(0x8e, 0x15);
            this.txtPassword.TabIndex = 1;
            this.label1.AutoSize = true;
            this.label1.Font = new Font("Tahoma", 10f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.label1.Location = new Point(10, 0x18);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x4a, 0x11);
            this.label1.TabIndex = 2;
            this.label1.Text = "Username:";
            this.label2.AutoSize = true;
            this.label2.Font = new Font("Tahoma", 10f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.label2.Location = new Point(10, 50);
            this.label2.Name = "label2";
            this.label2.Size = new Size(0x47, 0x11);
            this.label2.TabIndex = 3;
            this.label2.Text = "Password:";
            this.btnLogin.DialogResult = DialogResult.OK;
            this.btnLogin.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.btnLogin.Location = new Point(0x6f, 0x18d);
            this.btnLogin.Name = "btnLogin";
            this.btnLogin.Size = new Size(0x4b, 0x17);
            this.btnLogin.TabIndex = 5;
            this.btnLogin.Text = "OK";
            this.btnLogin.UseVisualStyleBackColor = true;
            this.btnLogin.Click += new EventHandler(this.btnLogin_Click);
            this.label4.AutoSize = true;
            this.label4.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.label4.Location = new Point(0x38, 0x76);
            this.label4.Name = "label4";
            this.label4.Size = new Size(0x41, 13);
            this.label4.TabIndex = 7;
            this.label4.Text = "You need to";
            this.lblRegister.AutoSize = true;
            this.lblRegister.Cursor = Cursors.Hand;
            this.lblRegister.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.lblRegister.ForeColor = System.Drawing.Color.RoyalBlue;
            this.lblRegister.Location = new Point(0x76, 0x76);
            this.lblRegister.Name = "lblRegister";
            this.lblRegister.Size = new Size(100, 13);
            this.lblRegister.TabIndex = 9;
            this.lblRegister.Text = "register an account";
            this.lblRegister.Click += new EventHandler(this.lblRegister_Click);
            this.label6.AutoSize = true;
            this.label6.Location = new Point(14, 0x66);
            this.label6.Name = "label6";
            this.label6.Size = new Size(0x157, 13);
            this.label6.TabIndex = 10;
            this.label6.Text = "________________________________________________________";
            this.label7.AutoSize = true;
            this.label7.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.label7.Location = new Point(0xd7, 0x76);
            this.label7.Name = "label7";
            this.label7.Size = new Size(0x69, 13);
            this.label7.TabIndex = 11;
            this.label7.Text = "before you can login";
            this.cbStartup.AutoSize = true;
            this.cbStartup.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.cbStartup.Location = new Point(0x63, 0x5c);
            this.cbStartup.Name = "cbStartup";
            this.cbStartup.Size = new Size(0xa8, 0x11);
            this.cbStartup.TabIndex = 12;
            this.cbStartup.Text = "Startup when Windows starts";
            this.cbStartup.UseVisualStyleBackColor = true;
            this.cbStartup.CheckedChanged += new EventHandler(this.cbStartup_CheckedChanged);
            this.groupBox1.Controls.Add(this.label2);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.groupBox1.Location = new Point(13, 13);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(0x15c, 0xb7);
            this.groupBox1.TabIndex = 13;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Account settings";
            this.groupBox2.Controls.Add(this.txtProxyDomain);
            this.groupBox2.Controls.Add(label5);
            this.groupBox2.Controls.Add(label2);
            this.groupBox2.Controls.Add(this.cbProxy);
            this.groupBox2.Controls.Add(label3);
            this.groupBox2.Controls.Add(label4);
            this.groupBox2.Controls.Add(this.txtProxyUsername);
            this.groupBox2.Controls.Add(this.txtProxyPassword);
            this.groupBox2.Controls.Add(this.label3);
            this.groupBox2.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.groupBox2.Location = new Point(13, 0xc9);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new Size(0x15c, 0xbd);
            this.groupBox2.TabIndex = 14;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Proxy settings";
            this.txtProxyDomain.Enabled = false;
            this.txtProxyDomain.Location = new Point(0x5c, 0x61);
            this.txtProxyDomain.Name = "txtProxyDomain";
            this.txtProxyDomain.Size = new Size(0x8e, 0x15);
            this.txtProxyDomain.TabIndex = 0x16;
            this.cbProxy.AutoSize = true;
            this.cbProxy.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.cbProxy.Location = new Point(0x5c, 0x16);
            this.cbProxy.Name = "cbProxy";
            this.cbProxy.Size = new Size(0xca, 0x11);
            this.cbProxy.TabIndex = 0x11;
            this.cbProxy.Text = "Proxy server requires authentication";
            this.cbProxy.UseVisualStyleBackColor = true;
            this.cbProxy.CheckedChanged += new EventHandler(this.cbProxy_CheckedChanged);
            this.txtProxyUsername.Enabled = false;
            this.txtProxyUsername.Location = new Point(0x5c, 0x2d);
            this.txtProxyUsername.Name = "txtProxyUsername";
            this.txtProxyUsername.Size = new Size(0x8e, 0x15);
            this.txtProxyUsername.TabIndex = 15;
            this.txtProxyPassword.Enabled = false;
            this.txtProxyPassword.Location = new Point(0x5c, 0x47);
            this.txtProxyPassword.Name = "txtProxyPassword";
            this.txtProxyPassword.PasswordChar = '*';
            this.txtProxyPassword.Size = new Size(0x8e, 0x15);
            this.txtProxyPassword.TabIndex = 15;
            this.label3.AutoSize = true;
            this.label3.Location = new Point(4, 0x72);
            this.label3.Name = "label3";
            this.label3.Size = new Size(0x157, 13);
            this.label3.TabIndex = 15;
            this.label3.Text = "________________________________________________________";
            this.btnCancel.DialogResult = DialogResult.Cancel;
            this.btnCancel.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.btnCancel.Location = new Point(0xba, 0x18d);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new Size(0x4b, 0x17);
            this.btnCancel.TabIndex = 15;
            this.btnCancel.Text = "Cancel";
            this.btnCancel.UseVisualStyleBackColor = true;
            this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
            base.AcceptButton = this.btnLogin;
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            this.BackColor = System.Drawing.Color.White;
            base.CancelButton = this.btnCancel;
            base.ClientSize = new Size(0x175, 0x1ac);
            base.Controls.Add(this.btnCancel);
            base.Controls.Add(this.groupBox2);
            base.Controls.Add(this.cbStartup);
            base.Controls.Add(this.label7);
            base.Controls.Add(this.label6);
            base.Controls.Add(this.lblRegister);
            base.Controls.Add(label);
            base.Controls.Add(this.label4);
            base.Controls.Add(this.btnLogin);
            base.Controls.Add(this.txtPassword);
            base.Controls.Add(this.txtUsername);
            base.Controls.Add(this.groupBox1);
            this.Font = new Font("Tahoma", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            base.FormBorderStyle = FormBorderStyle.FixedDialog;
            base.MaximizeBox = false;
            base.MinimizeBox = false;
            base.Name = "Userdata";
            this.RightToLeftLayout = true;
            base.ShowIcon = false;
            base.ShowInTaskbar = false;
            this.Text = "User credentials";
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            base.ResumeLayout(false);
            base.PerformLayout();
        }

        private void lblRegister_Click(object sender, EventArgs e)
        {
            Process.Start("http://www.freerainbowtables.com/");
        }
    }
}

